/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import app.FrameController;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.prefs.Preferences;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Une JFrame qui permet d'afficher totues les informations utiles au fonctionnement du logiciel. Propose un "mode test"
 * @author isen
 */
public class AppFrame extends javax.swing.JFrame {
    final ControlListener  l;
    final Preferences prefs;
    /**
     * 
     */
    public static final String OPTIONS_COMMAND = "options";

    /**
     * Creates new form NewJFrame
     * Construit une Frame sans la relier à un controleur
     */
    public AppFrame(){
        prefs = Preferences.systemNodeForPackage(FrameController.class);
        
        l = new ControlListener(){

            @Override
            public void onClose() {
                //nothing happens
            }

            @Override
            public void speedChange() {
                //nothing happens
            }

            @Override
            public void openOptionsPane() {
               //nothing happens
            }
            
        };
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setPreferredSize(new Dimension(600,600));
        this.setMinimumSize(new Dimension(300,300));
        
    }
    

    /**
     * Constructeur par défaut
     * 
     * 
     * @param fl
     * Listener fourni par le controleur pour être informé des actions de l'utilisateur sur la Frame
     * @param prefs
     * Préférences du programme fournies par le controleur
     */
    public AppFrame(final ControlListener  fl, Preferences prefs) {
        this.prefs = prefs;
        this.l = fl;
        initComponents();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new WindowAdapter(){

            @Override
            public void windowClosed(WindowEvent e) {
                l.onClose();
                super.windowClosed(e);
            }
            
        });
        this.setPreferredSize(new Dimension(600,600));
        this.setMinimumSize(new Dimension(300,300));
        
        this.setVisible(true);
        
    }

 

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        slopePanel = new javax.swing.JPanel();
        slopeNeg = new javax.swing.JProgressBar();
        slopePos = new javax.swing.JProgressBar();
        slopeLabel = new javax.swing.JLabel();
        maxSlope = new javax.swing.JLabel();
        minSlope = new javax.swing.JLabel();
        speedPanel = new javax.swing.JPanel();
        speedLabel = new javax.swing.JLabel();
        speedSlider = new javax.swing.JSlider();
        speedUp = new javax.swing.JCheckBox();
        infoPanel = new javax.swing.JPanel();
        distanceLabel = new javax.swing.JLabel();
        power = new javax.swing.JPanel();
        totalPower = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        userPower = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        torquePower = new javax.swing.JLabel();
        energy = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        totalEnergy = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        userEnergy = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        torqueEnergy = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        captorsState = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        file = new javax.swing.JMenu();
        autoReconnect = new javax.swing.JCheckBoxMenuItem();
        jMenu2 = new javax.swing.JMenu();
        options = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("DrivingApp");
        setName("DriverTestApp");

        slopePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Pente"));

        slopeNeg.setMaximum(0);
        slopeNeg.setMinimum(-20);
        slopeNeg.setToolTipText("");

        slopePos.setMaximum(20);

        slopeLabel.setText("0%");

        maxSlope.setText("+20%");

        minSlope.setText("-20%");

        javax.swing.GroupLayout slopePanelLayout = new javax.swing.GroupLayout(slopePanel);
        slopePanel.setLayout(slopePanelLayout);
        slopePanelLayout.setHorizontalGroup(
            slopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(slopePanelLayout.createSequentialGroup()
                .addComponent(slopeNeg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(slopeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(slopePos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(slopePanelLayout.createSequentialGroup()
                .addComponent(minSlope)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(maxSlope))
        );
        slopePanelLayout.setVerticalGroup(
            slopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, slopePanelLayout.createSequentialGroup()
                .addGroup(slopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(minSlope)
                    .addComponent(maxSlope))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(slopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(slopeLabel)
                    .addComponent(slopePos, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(slopeNeg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        speedPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Vitesse"));

        speedLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        speedLabel.setText("0");
        speedLabel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        speedSlider.setMaximum(30);
        speedSlider.setValue(0);
        speedSlider.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        speedSlider.setCursor(new java.awt.Cursor(java.awt.Cursor.MOVE_CURSOR));
        speedSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                speedSliderStateChanged(evt);
            }
        });

        speedUp.setText("x10");

        javax.swing.GroupLayout speedPanelLayout = new javax.swing.GroupLayout(speedPanel);
        speedPanel.setLayout(speedPanelLayout);
        speedPanelLayout.setHorizontalGroup(
            speedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(speedPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(speedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(speedSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(speedUp)
                .addGap(19, 19, 19))
        );
        speedPanelLayout.setVerticalGroup(
            speedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(speedPanelLayout.createSequentialGroup()
                .addGroup(speedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(speedLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(speedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(speedUp)))
                .addGap(1, 1, 1))
        );

        infoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Infos"));

        distanceLabel.setText("0");
        distanceLabel.setBorder(javax.swing.BorderFactory.createTitledBorder("distance parcourue"));

        power.setBorder(javax.swing.BorderFactory.createTitledBorder("puissance"));

        totalPower.setText("0");

        jLabel1.setText("puissance totale:");

        userPower.setText("0");

        jLabel2.setText("puissance de pédalage speed sensor:");

        jLabel5.setText("puisance de pédalage torque sensor:");

        torquePower.setText("0");

        javax.swing.GroupLayout powerLayout = new javax.swing.GroupLayout(power);
        power.setLayout(powerLayout);
        powerLayout.setHorizontalGroup(
            powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(powerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(powerLayout.createSequentialGroup()
                        .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(totalPower, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(userPower, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(powerLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(torquePower, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        powerLayout.setVerticalGroup(
            powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(powerLayout.createSequentialGroup()
                .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(totalPower))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userPower)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(powerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(torquePower))
                .addContainerGap())
        );

        energy.setBorder(javax.swing.BorderFactory.createTitledBorder("energie"));

        jLabel3.setText("energie totale");

        totalEnergy.setText("0");

        jLabel4.setText("energie de pédalage speed sensor:");

        userEnergy.setText("0");

        jLabel7.setText("energie de pedalage torque sensor:");

        torqueEnergy.setText("0");

        javax.swing.GroupLayout energyLayout = new javax.swing.GroupLayout(energy);
        energy.setLayout(energyLayout);
        energyLayout.setHorizontalGroup(
            energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(energyLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(energyLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(totalEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(energyLayout.createSequentialGroup()
                        .addGroup(energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(energyLayout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(18, 18, 18)
                                .addComponent(userEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(energyLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(18, 18, 18)
                                .addComponent(torqueEnergy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        energyLayout.setVerticalGroup(
            energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(energyLayout.createSequentialGroup()
                .addGroup(energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(totalEnergy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(userEnergy))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(energyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(torqueEnergy)))
        );

        jLabel6.setText("connexion aux capteurs:");

        captorsState.setBackground(new java.awt.Color(255, 0, 0));
        captorsState.setMinimumSize(new java.awt.Dimension(10, 10));
        captorsState.setPreferredSize(new java.awt.Dimension(10, 10));

        javax.swing.GroupLayout captorsStateLayout = new javax.swing.GroupLayout(captorsState);
        captorsState.setLayout(captorsStateLayout);
        captorsStateLayout.setHorizontalGroup(
            captorsStateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        captorsStateLayout.setVerticalGroup(
            captorsStateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout infoPanelLayout = new javax.swing.GroupLayout(infoPanel);
        infoPanel.setLayout(infoPanelLayout);
        infoPanelLayout.setHorizontalGroup(
            infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(power, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(energy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(distanceLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(infoPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(captorsState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(16, 16, 16))
        );
        infoPanelLayout.setVerticalGroup(
            infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoPanelLayout.createSequentialGroup()
                .addComponent(power, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(energy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 10, Short.MAX_VALUE))
            .addGroup(infoPanelLayout.createSequentialGroup()
                .addComponent(distanceLabel)
                .addGap(18, 18, 18)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(captorsState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(speedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(slopePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(infoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(speedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(slopePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(infoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        file.setText("file");

        autoReconnect.setSelected(true);
        autoReconnect.setText("Auto reconnect");
        autoReconnect.setToolTipText("Enable or disable auto reconnect");
        file.add(autoReconnect);

        jMenuBar1.add(file);

        jMenu2.setText("Edit");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });

        options.setText("Options");
        options.setActionCommand(AppFrame.OPTIONS_COMMAND);
        options.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                optionsActionPerformed(evt);
            }
        });
        jMenu2.add(options);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 110, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void speedSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_speedSliderStateChanged
        l.speedChange();
    }//GEN-LAST:event_speedSliderStateChanged

    private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu2ActionPerformed

    private void optionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsActionPerformed
        l.openOptionsPane();
    }//GEN-LAST:event_optionsActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AppFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AppFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AppFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AppFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AppFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBoxMenuItem autoReconnect;
    private javax.swing.JPanel captorsState;
    private javax.swing.JLabel distanceLabel;
    private javax.swing.JPanel energy;
    private javax.swing.JMenu file;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel maxSlope;
    private javax.swing.JLabel minSlope;
    private javax.swing.JMenuItem options;
    private javax.swing.JPanel power;
    private javax.swing.JLabel slopeLabel;
    private javax.swing.JProgressBar slopeNeg;
    private javax.swing.JPanel slopePanel;
    private javax.swing.JProgressBar slopePos;
    private javax.swing.JLabel speedLabel;
    private javax.swing.JPanel speedPanel;
    private javax.swing.JSlider speedSlider;
    private javax.swing.JCheckBox speedUp;
    private javax.swing.JLabel torqueEnergy;
    private javax.swing.JLabel torquePower;
    private javax.swing.JLabel totalEnergy;
    private javax.swing.JLabel totalPower;
    private javax.swing.JLabel userEnergy;
    private javax.swing.JLabel userPower;
    // End of variables declaration//GEN-END:variables

    //<editor-fold defaultstate="collapsed" desc=" setters declaration">
    /**
     * Met à jour l'indication de vitesse
     * @param speed
     * 
     */
    public void setSpeed(int speed){
        speedLabel.setText(Integer.toString(speed));
        
    }


    
    
    /**
     * Met à jour l'indication de la pente actuelle
     * @param slope
     */
    public void setSlope (int slope){
        if (slope >20) slope = 20;
        if (slope<-20) slope = -20;
        slopeLabel.setText(Integer.toString(slope));
        if (slope>=0){
                                
                                slopePos.setValue(slope);
                                slopeNeg.setValue(0);
                            }else{
                                slopePos.setValue(0);
                                slopeNeg.setValue(slope);
                            }
    }
    /**
     * 
     * @param power
     */
    public void setTotalPower(int power){
        totalPower.setText(Integer.toString(power));
    }
    /**
     * 
     * @param power
     */
    public void setUserPower(int power){
        userPower.setText(Integer.toString(power));
    }
    
    
    public void setTorquePower(int power){
        torquePower.setText(Integer.toString(power));
    }
    /**
     * 
     * @param distance
     */
    public void setDistance(int distance){
        this.distanceLabel.setText(Integer.toString(distance));
    }


        
    
    //</editor-fold>

    
    
    /**
     * 
     * @return
     */
    public int speedChanged() {
        int s = speedUpMod()*speedSlider.getValue();
        speedLabel.setText(Integer.toString(s));
        return s;
    }
    /**
     * 
     * @return
     */
    public Object getSpeedSlider() {
        return this.speedSlider;
    }
    /**
     * 
     * @return
     */
    public Object getSpeedUp(){
        return this.speedUp;
    }

    /**
     * 
     * @return
     */
    public Object getOptions() {
        return options;
        
    }
    
    
    /**
     * 
     * @return
     */
    public int speedUpMod(){
        if(this.speedUp.isSelected()) return 10;
        return 1;
    }

    /**
     * 
     * @param energy
     */
    public void setTotalEnergy(double energy) {
         DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        this.totalEnergy.setText(df.format(energy));
    }

    /**
     * 
     * @param userEnergy
     */
    public void setUserEnergy(double userEnergy) {
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        
        this.userEnergy.setText(df.format(userEnergy));
    }
    public void setTorqueEnergy(double userEnergy) {
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        
        this.torqueEnergy.setText(df.format(userEnergy));
    }
    
    public void setCaptorsConnected(){
        this.captorsState.setBackground(Color.GREEN);
    }
    public void setCaptorsDisconnected(){
        this.captorsState.setBackground(Color.RED);
    }
}
